--[[############ *Copyleft @2009-2010 Ciaho #################]]
local minFPS
local maxPing 


function getSettings()
	maxPing = get("maxPing")
	minFPS = get("minFPS")
end

function start(res)
	if res == getThisResource() then
		getSettings()
		if get("enableFPSColumn")=="true" then
			call(getResourceFromName("scoreboard"), "addScoreboardColumn", "FPS")
		end
	end
end
addEventHandler( "onResourceStart", getRootElement(), start )

function kick (reason)
	kickPlayer(source,getElementByIndex("console", 0),reason)
end
addEvent( "onkikuj", true )
addEventHandler( "onkikuj", getRootElement(), kick )

function stopujemy(res)
	if res == getThisResource() then
		call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "FPS")
	end
end
addEventHandler( "onResourceStop", getRootElement(), stopujemy )


function isPlayerAdmin(gracz)
  local acc = getPlayerAccount ( gracz )
  local name = getAccountName ( acc )
  local Ad = isObjectInACLGroup ( "user." .. name, aclGetGroup ( "Admin" ) )
  return Ad
end

function changeMaxPing(source, commandName, maxPing)
	if isPlayerAdmin(source) == true then
		if tonumber(maxPing) then
		changeSettings("maxPing",maxPing)
		outputChatBox("Value succesfully changed!",source,255,0,0)
		else
		outputChatBox("Wrong value!",source,255,0,0)
		end
		else
		outputChatBox("You are not Admin!",source,255,0,0)
	end
end
addCommandHandler("maxping",changeMaxPing)

function changeMinFPS (source, commandName, minFPS)
	if isPlayerAdmin(source) == true then
		if tonumber(minFPS) then
		changeSettings("minFPS",minFPS)
		outputChatBox("Value succesfully changed!",source,255,0,0)
		else
		outputChatBox("Wrong value!",source,255,0,0)
		end
		else
		outputChatBox("You are not Admin!",source,255,0,0)
	end
end
addCommandHandler("minfps",changeMinFPS)

function changeSettings(setting,arg)
	if setting == "maxPing" and tonumber(arg) then
		triggerClientEvent(getRootElement(),"changeConf",getRootElement(),"ping",tonumber(arg))
		set("maxPing",tonumber(arg))
		maxPing = tonumber(arg)
	elseif tonumber(arg) then
		triggerClientEvent(getRootElement(),"changeConf",getRootElement(),"fps",tonumber(arg))
		set("minFPS",tonumber(arg))
		minFPS = tonumber(arg)
	end
end

function sendSettings ()
triggerClientEvent(source,"changeConf",getRootElement(),"fps",minFPS)
triggerClientEvent(source,"changeConf",getRootElement(),"ping",maxPing)
end

addEvent("getPingkickerSettings",true)
addEventHandler("getPingkickerSettings",getRootElement(),sendSettings)